package com.xuelang.pipeline.entry.task;

import com.xuelang.pipeline.app.task.TaskDefService;
import com.xuelang.pipeline.client.common.request.PageParam;
import com.xuelang.pipeline.client.common.result.ApiResult;
import com.xuelang.pipeline.client.common.result.PageRecord;
import com.xuelang.pipeline.client.task.ITaskDefService;
import com.xuelang.pipeline.client.task.dto.TaskDefDTO;
import com.xuelang.pipeline.client.task.dto.TaskDefQuery;
import com.xuelang.pipeline.client.task.dto.TaskTypeFormDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 流水线任务定义服务web控制类
 *
 * @author xiwen.zxg
 * @since 2024/5/15
 */
@Slf4j
@RestController
@RequestMapping("/task-def")
public class TaskDefController implements ITaskDefService {

    @Autowired
    private TaskDefService taskDefService;

    @Override
    public ApiResult<PageRecord<TaskDefDTO>> pageTaskDefList(PageParam<TaskDefQuery> dtoPageParam) {
        return ApiResult.success(taskDefService.pageList(dtoPageParam));
    }

    @Override
    public ApiResult<List<TaskDefDTO>> conditionalTaskDefList(TaskDefQuery taskDefQuery) {
        return ApiResult.success(taskDefService.list(taskDefQuery));
    }

    @Override
    public ApiResult<List<TaskTypeFormDTO>> conditionalTaskDefAssemblyList(TaskDefQuery taskDefQuery) {
        return ApiResult.success(taskDefService.assemblyList(taskDefQuery));
    }

    @Override
    public ApiResult<Boolean> addTaskDef(TaskDefDTO taskDefDTO) {
        return ApiResult.success(taskDefService.add(taskDefDTO));
    }

    @Override
    public ApiResult<Boolean> updateTaskDef(TaskDefDTO taskDefDTO) {
        return ApiResult.success(taskDefService.update(taskDefDTO));
    }

    @Override
    public ApiResult<Boolean> deleteTaskDef(String uuid) {
        return ApiResult.success(taskDefService.delete(uuid));
    }

    @Override
    public ApiResult<TaskDefDTO> queryTaskDef(String uuid) {
        return ApiResult.success(taskDefService.query(uuid));
    }
}